home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
sos3-2.lha
/
src
/
agg
/
agg.sos
< prev
next >
Wrap
Text File
|
1991-10-24
|
20KB
|
523 lines
/* --------------------------------------------------------------------------
* Copyright 1992 by Forschungszentrum Informatik (FZI)
*
* You can use and distribute this software under the terms of the licence
* you should have received along with this program.
* If not or if you want additional information, write to
* Forschungszentrum Informatik, "STONE", Haid-und-Neu-Strasse 10-14,
* D-7500 Karlsruhe 1, Germany.
* --------------------------------------------------------------------------
*/
/* ************************************************************************ */
/* SOS aggregate classes */
/* **************************** ************** **************************** */
with extern;
schema agg
{
typedef sos_Int Index;
// ****************************** Aggregate *******************************
class sos_Aggregate
{
public:
sos_Bool is_empty (); // TRUE iff card == 0
void clear(); // iterative application of remove_at
// until the Aggregate is empty
// ** Abstract operations **
// must be implemented by specific classes derived from sos_Aggregate
abstract sos_Int card (); // return the cardinality
// ** sos_Cursor operations (abstract) **
abstract sos_Cursor open_cursor (sos_Container = TEMP_CONTAINER);
// create a new sos_Cursor for
// this Aggregate.
abstract void close_cursor (sos_Cursor);
// remove the sos_Cursor
abstract sos_Cursor duplicate (sos_Cursor);
// create a new cursor on the same
// entity
abstract sos_Bool is_valid (sos_Cursor);
// checks if the cursor is exceeded
abstract void remove_at (sos_Cursor);
// remove the 'current' entry from
// the Aggregate and position the
// cursor to the succeeding entry
abstract sos_Bool to_first (sos_Cursor);
// set the sos_Cursor to the first
// entity
abstract sos_Bool to_last (sos_Cursor);
// set the sos_Cursor to the last entity
abstract sos_Bool to_succ (sos_Cursor, sos_Int = 1);
// position the cursor on the
// succeeding entity; return TRUE
// if such an entity exists
abstract sos_Bool to_pred (sos_Cursor, sos_Int = 1);
// position the cursor on the
// preceding entity; return TRUE
// iff such an entity exists
}; // ** sos_Aggregate **
class Collection<Entity> (sos_Bool based_on_equal = FALSE) : sos_Aggregate
// the create parameter determines whether the is_element()
// function is based on the 'equal' or the '==' function
{
public:
sos_Bool is_element (Entity); // check the membership of the Entity
// ** Abstract operations **
// must be implemented by specific classes derived from Aggregate
abstract Entity get (sos_Cursor); // return the 'current' Entity
protected:
sos_Bool based_on_equal = based_on_equal;
}; // ** Collection<Entity> **
// **************************** Association *******************************
class Association<Role1, Role2> (sos_Bool role1_based_on_equal = FALSE,
sos_Bool role2_based_on_equal = FALSE)
: sos_Aggregate
{
public:
sos_Bool is_role1 (Role1); // check the membership of the role1
sos_Bool is_role2 (Role2); // check the membership of the role2
// ** Abstract operations **
// must be implemented by specific classes derived from Aggregate
abstract Role1 get_role1 (sos_Cursor); // return the 'current' role1
abstract Role2 get_role2 (sos_Cursor); // return the 'current' role2
protected:
sos_Bool role1_based_on_equal = role1_based_on_equal;
sos_Bool role2_based_on_equal = role2_based_on_equal;
}; // ** Association<Role1, Role2> **
// ******************************* sos_Cursor **************************
class sos_Cursor (sos_Aggregate domain)
{
public:
sos_Node current; // the current node
sos_Bool defined_for (sos_Aggregate);// return TRUE iff the sos_Cursor has
// been opened for sos_Aggregate
protected:
static void local_initialize (sos_Cursor);
private:
sos_Aggregate domain = domain; // aggregate the cursor is opened for
}; // ** sos_Cursor **
// ****************************** List *******************************
class List<Entity> (sos_Bool based_on_equal = FALSE)
: Collection<Entity> (based_on_equal)
{
public:
void append (Entity); // appends the element
void insert (Index, Entity); // insert the element before the
// specified position
// (i>l.card () | i==0) <=> l += e
void remove (Index); // remove the element at the
// specified position
Entity get_nth (Index); // return the element
// at the specified position
void set_nth (Index, Entity); // set the given element
// at the specified position
// ** List operators **
void operator+= (List<Entity>); // appends another list
// ** sos_Cursor operations **
Index current_pos (sos_Cursor); // returns current position
sos_Bool move_cursor (sos_Cursor, Index); // moves cursor to position
void insert_before (sos_Cursor, Entity);
void insert_after (sos_Cursor, Entity);
void set (sos_Cursor, Entity); // replace the 'current' entity
// by the given Entity
// ** Redefinitions **
Entity get (sos_Cursor); // redefined (-> Collection)
void remove_at (sos_Cursor); // redefined (-> sos_Aggregate)
sos_Int card (); // redefined (-> sos_Aggregate)
sos_Cursor open_cursor (sos_Container = TEMP_CONTAINER);
// redefined (-> sos_Aggregate)
void close_cursor (sos_Cursor); // redefined (-> sos_Aggregate)
sos_Cursor duplicate (sos_Cursor); // redefined (-> sos_Aggregate)
sos_Bool is_valid(sos_Cursor); // redefined (-> sos_Aggregate)
sos_Bool to_first(sos_Cursor); // redefined (-> sos_Aggregate)
sos_Bool to_last(sos_Cursor); // redefined (-> sos_Aggregate)
sos_Bool to_succ (sos_Cursor, sos_Int=1);// redefined (-> sos_Aggregate)
sos_Bool to_pred (sos_Cursor, sos_Int=1);// redefined (-> sos_Aggregate)
protected:
static void local_initialize (List<Entity>);
static void local_finalize (List<Entity>);
static void local_assign (List<Entity>, sos_Object);
static sos_Bool local_equal (List<Entity>, sos_Object, sos_Eq_kind);
static sos_Int local_hash_value (List<Entity>);
private:
local sos_List_node first, last;
sos_Int cardinality;
}; // ** List<Entity> **
// ****************************** Array *******************************
class Array<Entity> (Index bottom, Index top, sos_Bool based_on_equal = FALSE)
: Collection<Entity> (based_on_equal)
{
public:
Index get_bottom ();
Index get_top ();
Entity get_nth (Index); // returns the element at the
// specified position
void set_nth (Index, Entity);// replaces the element at the given
// position by the given element
void shift (Index start, // shifts from given start index,
sos_Int number); // the specif. number of elements
// direction: + right / - left
void rotate (sos_Int number); // rotates number of positions
// ** Array operators **
Entity operator[] (Index);
// ** sos_Cursor operations **
Index current_pos (sos_Cursor); // returns current position
sos_Bool move_cursor (sos_Cursor, Index); // moves cursor to Index position
void set (sos_Cursor, Entity); // replace the 'current' entity
// by the given Entity
// ** Redefinitions **
sos_Int size(); // redefined (-> sos_Object)
Entity get (sos_Cursor); // redefined (-> Collection)
void remove_at (sos_Cursor); // redefined (-> sos_Aggregate)
sos_Int card (); // redefined (-> sos_Aggregate)
sos_Cursor open_cursor (sos_Container = TEMP_CONTAINER);
// redefined (-> sos_Aggregate)
void close_cursor (sos_Cursor); // redefined (-> sos_Aggregate)
sos_Cursor duplicate (sos_Cursor); // redefined (-> sos_Aggregate)
sos_Bool is_valid(sos_Cursor); // redefined (-> sos_Aggregate)
sos_Bool to_first(sos_Cursor); // redefined (-> sos_Aggregate)
sos_Bool to_last(sos_Cursor); // redefined (-> sos_Aggregate)
sos_Bool to_succ (sos_Cursor, sos_Int=1);// redefined (-> sos_Aggregate)
sos_Bool to_pred (sos_Cursor, sos_Int=1);// redefined (-> sos_Aggregate)
protected:
static void local_initialize (Array<Entity>);
static void local_finalize (Array<Entity>);
static void local_assign (Array<Entity>, sos_Object);
static sos_Bool local_equal (Array<Entity>, sos_Object, sos_Eq_kind);
static sos_Int local_hash_value (Array<Entity>);
private:
Index bottom_index = bottom;
Index top_index = top;
sos_Offset address;
sos_Int element_size();
}; // ** Array<Entity> **
// ******************************* Mapping *******************************
class Mapping<Key, Info> (sos_Bool list_cursor = FALSE,
sos_Bool key_based_on_equal = FALSE,
sos_Bool info_based_on_equal = FALSE)
: Association<Key, Info> (key_based_on_equal, info_based_on_equal)
// list_cursor allowes that the mapping could be dynamically modified
// while a cursor iterates over the structur.
{
public:
sos_Bool is_key (Key); // checks if there's an entry for
// the given key
sos_Bool is_info (Info); // checks if there's an entry for
// the given info
void insert (Key, Info); // if there already exists such an
// entry, the Info will be
// replaced
void remove (Key); // deletes an entry
Info operator[] (Key); // associative access
// ** sos_Cursor operations **
Key get_key (sos_Cursor); // get the current Key value
Info get_info (sos_Cursor); // set the current Info value
void set_info (sos_Cursor, Info); // set the current Info value
void move_cursor (sos_Cursor, Key); // move cursor to Key
void insert_before (sos_Cursor, Key, Info); // insert (Key, Info)
// before cursor position
void insert_after (sos_Cursor, Key, Info); // insert (Key,Info)
// after cursor position
// ** Redefinitions **
sos_Int size (); // redefined (-> sos_Object)
sos_Bool is_role1 (Key); // redefined (-> Association)
sos_Bool is_role2 (Info); // redefined (-> Association)
Key get_role1 (sos_Cursor); // redefined (-> Association)
Info get_role2 (sos_Cursor); // redefined (-> Association)
void clear(); // redefined (-> Association)
void remove_at (sos_Cursor); // redefined (-> sos_Aggregate)
sos_Int card (); // redefined (-> sos_Aggregate)
sos_Cursor open_cursor (sos_Container = TEMP_CONTAINER);
// redefined (-> sos_Aggregate)
void close_cursor(sos_Cursor); // redefined (-> sos_Aggregate)
sos_Cursor duplicate(sos_Cursor); // redefined (-> sos_Aggregate)
sos_Bool is_valid(sos_Cursor); // redefined (-> sos_Aggregate)
sos_Bool to_first(sos_Cursor); // redefined (-> sos_Aggregate)
sos_Bool to_last(sos_Cursor); // redefined (-> sos_Aggregate)
sos_Bool to_succ (sos_Cursor, sos_Int=1); // redefined (-> sos_Aggregate)
sos_Bool to_pred (sos_Cursor, sos_Int=1); // redefined (-> sos_Aggregate)
protected:
static void local_initialize (Mapping<Key,Info>);
static void local_finalize (Mapping<Key,Info>);
static void local_assign (Mapping<Key,Info>, sos_Object);
static sos_Bool local_equal (Mapping<Key,Info>, sos_Object, sos_Eq_kind);
static sos_Int local_hash_value (Mapping<Key,Info>);
private:
sos_Int cardinality;
sos_Object first_object;
sos_Object last_object;
sos_Bool list_cursor = list_cursor;
sos_Offset no_of_pages_offset;
sos_Int no_of_pages;
sos_Int no_of_page_lists;
sos_Int global_depth;
sos_Int ht_entries;
sos_Int ht_offset;
void init_table ();
void increase_hash_table ();
void decrease_hash_table ();
void insert_in_list (sos_Object, sos_Object, sos_Object, sos_Object);
void insert_in_page_list (sos_Container, sos_Bool, sos_Bool,
sos_Offset, sos_Int, sos_Object,
sos_Object, sos_Object, sos_Object);
sos_Object remove_from_page_list (sos_Container, sos_Bool, sos_Bool,
sos_Offset, sos_Int, sos_Object);
sos_Bool assemble_page (sos_Offset, sos_Char, sos_Int);
void split_page (sos_Container,sos_Bool, sos_Offset, sos_Char,
sos_Int, sos_Int);
sos_Object search_succ_pred (sos_Object, sos_Int);
void write_succ_pred (sos_Container,sos_Bool,sos_Bool,sos_Object,
sos_Bool, sos_Object);
}; // ** Mapping<Key, Info> **
// ****************************** Bag *******************************
class Bag<Entity> (sos_Bool list_cursor = TRUE,
sos_Bool based_on_equal = FALSE)
: Collection<Entity> (based_on_equal)
// list_cursor allowes that the bag could be dynamically modified
// while a cursor iterates over the structur.
{
public:
sos_Int insert (Entity); // insert (perhaps again)
sos_Int remove (Entity); // remove (only one occurrence)
void eliminate (Entity); // removes all entries of Entity
sos_Int occurrences (Entity); // number of occ. of Entity in Bag
void operator+= (Bag<Entity>); // addition
void operator-= (Bag<Entity>); // difference
void operator*= (Bag<Entity>); // intersection
sos_Bool operator< (Bag<Entity>); // part of
sos_Bool operator<= (Bag<Entity>); // part of
sos_Bool operator> (Bag<Entity>); // contains
sos_Bool operator>= (Bag<Entity>); // contains
void max_union (Bag<Entity>); // union
// ** sos_Cursor operations **
sos_Int entity_occurs (sos_Cursor); // number of occ. of current Entity
sos_Bool to_diff_succ (sos_Cursor, sos_Int = 1);
sos_Bool to_diff_pred (sos_Cursor, sos_Int = 1);
// ** Redefinitions **
sos_Bool is_element (Entity); // redefined (-> Collection)
Entity get (sos_Cursor); // redefined (-> Collection)
void clear(); // redefined (-> Collection)
void remove_at (sos_Cursor); // redefined (-> sos_Aggregate)
sos_Int card (); // redefined (-> sos_Aggregate)
sos_Cursor open_cursor (sos_Container = TEMP_CONTAINER);
// redefined (-> sos_Aggregate)
void close_cursor (sos_Cursor); // redefined (-> sos_Aggregate)
sos_Cursor duplicate (sos_Cursor); // redefined (-> sos_Aggregate)
sos_Bool is_valid(sos_Cursor); // redefined (-> sos_Aggregate)
sos_Bool to_first(sos_Cursor); // redefined (-> sos_Aggregate)
sos_Bool to_last(sos_Cursor); // redefined (-> sos_Aggregate)
sos_Bool to_succ (sos_Cursor, sos_Int=1);// redefined (-> sos_Aggregate)
sos_Bool to_pred (sos_Cursor, sos_Int=1);// redefined (-> sos_Aggregate)
protected:
static void local_initialize (Bag<Entity>);
static void local_finalize (Bag<Entity>);
static void local_assign (Bag<Entity>, sos_Object);
static sos_Bool local_equal (Bag<Entity>, sos_Object, sos_Eq_kind);
static sos_Int local_hash_value (Bag<Entity>);
private:
sos_Int cardinality;
Mapping<Entity,sos_Int> m;
void search_succ_pred (sos_Bag_node, Index, sos_Object&, sos_Int&,
sos_Int&);
void write_current (sos_Cursor, sos_Object, sos_Int, sos_Int);
sos_Int get_no_of_elements (Mapping<Entity,sos_Int>, sos_Object);
sos_Int set_no_of_elements (Mapping<Entity,sos_Int>, sos_Object,
sos_Int, sos_Int);
sos_Bool list_cursor = list_cursor;
}; // ** Bag<Entity> **
// ****************************** Set *******************************
class Set<Entity> (sos_Bool list_cursor = TRUE,
sos_Bool based_on_equal = FALSE)
: Collection<Entity> (based_on_equal)
// list_cursor allowes that the set could be dynamically modified
// while a cursor iterates over the structur.
{
public:
// ** Set operators **
void insert (Entity); // insertion - union (perhaps again)
void remove (Entity); // removal / difference
void operator+= (Set<Entity>); // addition
void operator-= (Set<Entity>); // difference
void operator*= (Set<Entity>); // intersection
sos_Bool operator< (Set<Entity>); // part of
sos_Bool operator<= (Set<Entity>); // part of
sos_Bool operator> (Set<Entity>); // contains
sos_Bool operator>= (Set<Entity>); // contains
// ** Redefinitions **
sos_Bool is_element (Entity); // redefined (-> Collection)
Entity get (sos_Cursor); // redefined (-> Collection)
void clear(); // redefined (-> Collection)
void remove_at (sos_Cursor); // redefined (-> sos_Aggregate)
sos_Int card (); // redefined (-> sos_Aggregate)
sos_Cursor open_cursor (sos_Container = TEMP_CONTAINER);
// redefined (-> sos_Aggregate)
void close_cursor (sos_Cursor); // redefined (-> sos_Aggregate)
sos_Cursor duplicate (sos_Cursor); // redefined (-> sos_Aggregate)
sos_Bool is_valid(sos_Cursor); // redefined (-> sos_Aggregate)
sos_Bool to_first(sos_Cursor); // redefined (-> sos_Aggregate)
sos_Bool to_last(sos_Cursor); // redefined (-> sos_Aggregate)
sos_Bool to_succ (sos_Cursor, sos_Int=1);// redefined (-> sos_Aggregate)
sos_Bool to_pred (sos_Cursor, sos_Int=1);// redefined (-> sos_Aggregate)
protected:
static void local_initialize (Set<Entity>);
static void local_finalize (Set<Entity>);
static void local_assign (Set<Entity>, sos_Object);
static sos_Bool local_equal (Set<Entity>, sos_Object, sos_Eq_kind);
static sos_Int local_hash_value (Set<Entity>);
private:
sos_Bool list_cursor = list_cursor;
Mapping<Entity,sos_Bool> m;
}; // ** Set<Entity> **
// ***************************** sos_Node *****************************
// only for sos_Internal use!
class sos_Node {};
// ************************** sos_Array_node **************************
class sos_Array_node : sos_Node
{
friend class Array;
private:
Index index;
}; // ** sos_Array_node **
// *************************** sos_List_node **************************
class sos_List_node : sos_Node
{
friend class List;
private:
local sos_List_node succ, pred;
sos_Object val; // contents of the node
void insert_before (sos_List_node);
void insert_after (sos_List_node);
void remove ();
sos_List_node succ (sos_Int steps = 1);
sos_List_node pred (sos_Int steps = 1);
}; // ** sos_List_node **
// ***************************** sos_Map_node *****************************
class sos_Map_node : sos_Node
{
friend class Mapping;
protected:
sos_Object key_val;
}; // ** sos_Map_node **
// ***************************** sos_Bag_node *****************************
class sos_Bag_node : sos_Map_node
{
friend class Bag;
private:
sos_Int tag_no;
sos_Int tag_max;
}; // ** sos_Bag_node **
} // ** schema agg **